package StringExercise;

import java.util.ArrayList;
import java.util.Random;

/**
 * ClassName:StringExercise002
 * Package:StringExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/17-17:55
 * @Version:v1.0
 */
public class StringExercise002 {
    /*
    生成验证码
    * 内容：可以是小写字母,也可以是大写字母,还可以是数字
    * 规则：
    * 1.长度是5
    * 2.内容是4位字母,1位数字
    * 3.其中数字只有1位,但是可以出现在任意的位置*/
    public static void main(String[] args) {
        //1.可以把所有大写字母,小写字母都放到一个数组当中A-65 a-97  32
        ArrayList<Character> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        String[] arr = new String[5];
        Random r = new Random();
        for (int i = 0; i < 26; i++) {
            list1.add((char) ('a' + i));
            list1.add((char) ('A' + i));
        }
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(list1.size());
            arr[i] = list1.get(index).toString();
        }
        for (int i = 0; i <= 9; i++) {
            list2.add(i);
        }
        int index1 = r.nextInt(list2.size());
        arr[4] = list2.get(index1).toString();
//        System.out.println(arr[4]);

        StringBuilder sb = new StringBuilder();
        int index2 = r.nextInt(arr.length);
        String temp = arr[4];
        arr[4] = arr[index2];
        arr[index2] = temp;
        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
        }

        System.out.println(sb.toString());
//        System.out.println(list2);
//        System.out.println(list1);


    }
}
